<template>
	<n-card :title="className">
		<!-- 学生模块 -->
		<el-table :data="tableData" style="width: 100%">
			<el-table-column
				prop="ename"
				width="270"
				label="实验"
			></el-table-column>
			<el-table-column
				prop="name"
				width="160"
				label="姓名"
			></el-table-column>
			<el-table-column
				prop="sid"
				label="学号"
				width="160"
			></el-table-column>
			<!-- <el-table-column prop="updateTime" label="提交时间"></el-table-column> -->
			<el-table-column label="操作" width="180">
				<template #default="scope">
					<el-button
						type="success"
						size="small"
						@click="goToCheckExp(scope.row)"
						>查看</el-button
					>
					<span ref="remind" id="remind"
						><svg
							t="1699345470823"
							class="icon"
							viewBox="0 0 1024 1024"
							version="1.1"
							xmlns="http://www.w3.org/2000/svg"
							p-id="1656"
							width="16"
							height="16"
						>
							<path
								d="M511.999907 511.999907m-511.999907 0a511.999907 511.999907 0 1 0 1023.999814 0 511.999907 511.999907 0 1 0-1023.999814 0Z"
								fill="#FF7650"
								p-id="1657"
							></path>
							<path
								d="M466.087479 2.029381A518.050815 518.050815 0 0 1 511.999907 0c282.763585 0 511.999907 229.227013 511.999907 511.999907 0 8.68538-0.195491 17.314906-0.633018 25.897886-15.12727 1.349818-30.440722 2.029381-45.912428 2.029382-282.763585 0-511.999907-229.227013-511.999907-511.999907 0-8.68538 0.2048-17.314906 0.633018-25.897887z"
								fill="#FFFFFF"
								opacity=".1"
								p-id="1658"
							></path>
							<path
								d="M214.109052 928.460631V875.054386h37.236357V614.399888c0-128.074449 92.364783-234.561121 214.109052-256.511953V279.272676h93.090892v78.615259C680.289622 379.838767 772.654405 486.325439 772.654405 614.399888v260.654498h37.236357v53.406245c-5.613381 4.030836-11.34778 7.959271-17.128724 11.75738H231.237776A510.529071 510.529071 0 0 1 214.109052 928.460631zM577.163531 567.854442h65.163625v260.654498h-65.163625V567.854442z"
								fill="#F8F0EF"
								p-id="1659"
							></path>
							<path
								d="M642.327156 1007.262071A512.88427 512.88427 0 0 1 511.999907 1023.999814c-45.037374 0-88.71562-5.818181-130.327249-16.737743V986.763457h260.654498v20.498614z"
								fill="#F8F0EF"
								p-id="1660"
							></path>
							<path
								d="M577.163531 567.854442h65.163625v260.654498h-65.163625z"
								fill="#FF7650"
								p-id="1661"
							></path>
						</svg>
					</span>
					<!-- <el-button type="warning" size="small">删除</el-button> -->
				</template>
			</el-table-column>
			<el-table-column label="删除">
				<template #default="scope">
					<el-popconfirm
						width="220"
						confirm-button-text="确定"
						cancel-button-text="取消"
						:icon="InfoFilled"
						icon-color="#626AEF"
						title="确定删除吗?"
						@confirm="Delete(scope.row)"
					>
						<template #reference>
							<el-button size="small" type="danger"
								>删除</el-button
							>
						</template>
					</el-popconfirm>
				</template>
			</el-table-column>
		</el-table>
	</n-card>
</template>
<script setup lang="ts">
//@ts-nocheck
import { getStudent, getCompleteExList, getExList, DelExp } from '@/api/request'
import { useGlobalStore } from '../../store/GlobalStore'
const store = useGlobalStore()
const tid = store.userInfo.tid
const route = useRoute()
const router = useRouter()
const result = ref([])
const result2 = ref([])
const sid = route.query.sid
const className = route.query.name
const remind = ref()
const jwtToken = localStorage.getItem('jwtToken')
const ws = new WebSocket(
	`ws://210.44.37.172:8082/message?id=${tid}&role=teacher`
)
ws.onopen = function (e) {
	console.log('连接成功')
	// ws.send(
	// 	// '{"rid":"2002","tid":"3000","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// )
	// ws.send(
	// 	'{"role":"student","sourceId":"sid","eid":"","rid":"2002","destId":"tid","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// )
}
ws.onmessage = function (e) {
	console.log(e.data, '接收返回的消息')
}
ws.onclose = function () {
	console.log('连接关闭')
}
ws.onerror = function () {
	console.log('连接出错')
}
onMounted(() => {
	// console.log('实验的代号', route.params.scope)
	console.log('remind', remind.value)
	const cid = route.query.cid
	console.log(route.query.cid)
	// console.log(router)
	getExList(jwtToken, cid).then((res) => {
		console.log(res.data.data, '实验列表')
		console.log()

		result.value = res.data.data
		result.value = result.value.map((item) => ({
			rid: item.id,
			eid: item.eid,
			sid: item.sid,
			cid: item.cid,
			name: item.name,
			ename: '',
			updateTime: item.startTime,
			state: item.state,
			classNum: item.classNum,
			grade: item.grade,
			college: item.college,
			major: item.major,
		}))
		result.value.forEach((ele) => {
			if (ele.state == 3) {
				result2.value.push(ele)
			}
		})
		console.log('result2', result2.value)

		result2.value.forEach((element) => {
			// 把下面的if else 结构一直写到20
			if (element.eid === '1') {
				element.ename = '液体黏滞系数的测定'
			} else if (element.eid === '2') {
				element.ename = '液体表面张力系数的测定'
			} else if (element.eid === '3') {
				element.ename = '刚体转动惯量的测定'
			} else if (element.eid === '4') {
				element.ename = '震动法测材料的杨氏模量'
			} else if (element.eid === '5') {
				element.eid = '用稳态法测定不良导体的导热系数'
			} else if (element.eid === '6') {
				element.eid = 'AD590 集成电路温度传感器的特性研究及应用'
			} else if (element.eid === '7') {
				element.eid = '用板式电势差计测电源电动势'
			} else if (element.eid === '8') {
				element.eid = '电子示波器的使用'
			} else if (element.eid === '9') {
				element.ename = '电表改装与校准'
			} else if (element.eid === '10') {
				element.ename = '密立根油滴实验'
			} else if (element.eid === '11') {
				element.eid = '霍尔效应的测量和应用'
			} else if (element.eid === '12') {
				element.eid = '铁磁材料的磁滞回线和磁化曲线的测量'
			} else if (element.eid === '13') {
				element.eid = '磁阻效应及磁阻传感器特性的研究'
			} else if (element.eid === '14') {
				element.eid = '声速的测定'
			} else if (element.eid === '15') {
				element.ename = '声速的测定'
			} else if (element.eid === '16') {
				element.ename = '用牛顿环仪测量透镜的曲率半径'
			} else if (element.eid === '17') {
				element.ename = '迈克尔逊干涉仪的调节与使用'
			} else if (element.eid === '18') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid == '19') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid === '20') {
				element.ename = '压电陶瓷特性研究'
			}
			// else if(element.name==='')
		})
		tableData.value = result2.value
		console.log('处理完的数据：', tableData.value)
	})
})

// 计算属性，定义title，当
const tableData = ref([])
const Delete = async (row) => {
	console.log(row)

	let res = await DelExp(jwtToken, row.rid)
	if (res.status == 200) {
		ElMessage({
			message: '删除成功',
			type: 'success',
		})
		location.reload()
	} else ElMessage.error('删除失败')
	console.log('Delete', res)
}
const goToCheckExp = (element) => {
	// console.log('学生的学号', res)

	// 把下面的if else 结构一直写到20
	if (element.eid === '1') {
		element.ename = '液体黏滞系数的测定'
	} else if (element.eid === '2') {
		element.ename = '液体表面张力系数的测定'
	} else if (element.eid === '3') {
		element.ename = '刚体转动惯量的测定'
	} else if (element.eid === '4') {
		element.ename = '震动法测材料的杨氏模量'
	} else if (element.eid === '5') {
		element.eid = '用稳态法测定不良导体的导热系数'
	} else if (element.eid === '6') {
		element.eid = 'AD590 集成电路温度传感器的特性研究及应用'
	} else if (element.eid === '7') {
		element.eid = '用板式电势差计测电源电动势'
	} else if (element.eid === '8') {
		element.eid = '电子示波器的使用'
	} else if (element.eid === '9') {
		element.ename = '电表改装与校准'
	} else if (element.eid === '10') {
		element.ename = '密立根油滴实验'
	} else if (element.eid === '11') {
		element.eid = '霍尔效应的测量和应用'
	} else if (element.eid === '12') {
		element.eid = '铁磁材料的磁滞回线和磁化曲线的测量'
	} else if (element.eid === '13') {
		element.eid = '磁阻效应及磁阻传感器特性的研究'
	} else if (element.eid === '14') {
		element.eid = '声速的测定'
	} else if (element.eid === '15') {
		element.ename = '声速的测定'
	} else if (element.eid === '16') {
		element.ename = '用牛顿环仪测量透镜的曲率半径'
	} else if (element.eid === '17') {
		element.ename = '迈克尔逊干涉仪的调节与使用'
	} else if (element.eid === '18') {
		element.ename = '用分光计测光波波长'
	} else if (element.eid == '19') {
		element.ename = '用分光计测光波波长'
	} else if (element.eid === '20') {
		element.ename = '压电陶瓷特性研究'
	}
	// else if(element.name==='')
	// console.log(element.eid, 'aaaaaaaaa')
	router.push({
		path: `/review-paper/${element.eid}`,
		query: {
			eid: element.eid,
			rid: element.rid,
			name: element.name,
			sid: element.sid,
			cid: element.cid,
			classNum: element.classNum,
			college: element.college,
			grade: element.grade,
			major: element.major,
		},
	})
}
</script>

<style lang="less" scoped>
.bottom-content {
	padding: 14px;
	text-align: center;

	.bottom {
		margin-top: 13px;
		line-height: 12px;
		display: flex;
		align-items: center;
		justify-content: center;

		.button {
			padding: 18px;
			min-height: auto;
		}
	}
}

.image {
	width: 100%;
	display: block;
}
#remind {
	display: inline-block;
	margin-left: 10px;
	padding-top: 18px;
	line-height: 20px;
	align-items: center;
	opacity: 0;
}
</style>
